// 地址相关的接口
import axios from "@/utils/axios";

// 获取总的地址列表
function getAddress() {
    return axios({
        method: "get",
        url: "/api/city",
        params: {},
    });
}

// 获取自己的地址列表
function getMyAddress() {
    return axios({
        method: "get",
        url: "/api/address",
        headers: { "x-token": localStorage.getItem("token") },
    });
}

// 添加地址
function addAddress(addressInfo) {
    return axios({
        method: "post",
        url: "/api/address",
        data: { ...addressInfo },
        headers: { "x-token": localStorage.getItem("token") },
    });
}

// 删除地址
function delAddress(address_id) {
    return axios({
        method: "delete",
        url: `/api/address/${address_id}`,
        headers: { "x-token": localStorage.getItem("token") },
    });
}

// 设置为默认地址
function setDefaultAddress(addressId) {
    return axios({
        method: "post",
        url: `/api/setDefault/${addressId}`,
        headers: { "x-token": localStorage.getItem("token") },
    });
}

// 创建物流信息
function createLogistics(id) {
    return axios({
        method: "post",
        url: "/api/createLogistics",
        data: { order_id: id },
        headers: { "x-token": localStorage.getItem("token") },
    });
}

// 获取物流信息
function getLogistics(id) {
    return axios({
        method: "get",
        url: "/api/getLogistics",
        params: { order_id: id },
        headers: { "x-token": localStorage.getItem("token") },
    });
}

export {
    getAddress,
    addAddress,
    delAddress,
    getMyAddress,
    setDefaultAddress,
    createLogistics,
    getLogistics,
};
